package com.hdaccp.foodsales.controller;


import com.hdaccp.foodsales.dao.shangpinDao;
import com.hdaccp.foodsales.dao.xiaoshouDao;
import com.hdaccp.foodsales.entity.Shangpin;
import com.hdaccp.foodsales.pojo.jingbanBean;
import com.hdaccp.foodsales.pojo.sptypeBean;
import com.hdaccp.foodsales.service.shangpinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/shangpin")
@Scope("prototype")
public class shangpinController {
    @Autowired
    private shangpinService shangpinService;
    @Autowired
    private shangpinDao shangpinDao;


    @RequestMapping("/query")
    @ResponseBody
    public Map<String,Object> querySearch(String sname,int offset, int limit){
        Map<String,Object> map = new HashMap<>() ;
        map.put("rows",shangpinService.findAll(sname,offset,limit)) ;
        map.put("total",shangpinService.findTotalCount(sname)) ;
        return  map ;
    }

    @RequestMapping("/getsid")
    @ResponseBody
    public Shangpin getsid(int sid){
        return shangpinService.getsid(sid);
    }

    @RequestMapping("/querytype")
    @ResponseBody
    public Map<String,List<sptypeBean>>querytype(){
        Map<String,List<sptypeBean>> map = new HashMap<>() ;
        List<sptypeBean> list =shangpinDao.qeurytype();
        map.put("sp",list);
        return map;
    }
}
